import 'package:fish_redux/fish_redux.dart';
import 'package:kunlun_gas/app_files.dart';

import 'action.dart';
import 'state.dart';

Effect<UserInfoEditViewState> buildEffect() {
  return combineEffects(<Object, Effect<UserInfoEditViewState>>{
    UserInfoEditViewAction.action: _onAction,
    UserInfoEditViewAction.onSubmit: _onSubmit,
  });
}

void _onAction(Action action, Context<UserInfoEditViewState> ctx) {}

void _onSubmit(Action action, Context<UserInfoEditViewState> ctx) async {
  int ret = await CommonUtils.showOKCanceltView(ctx.context, '确定修改用户联系方式？');
  if (ret == 1) {
    ResultData res = await CommonNetWork.editUserPhone(
      userID: ctx.state.userInfo.userID,
      userName: ctx.state.userInfo.userName,
      userPhone: ctx.state.phoneController.text,
    );
    if (res.success) {
      ctx.state.userInfo.phone = ctx.state.phoneController.text;
      Navigator.pop(ctx.context);
      bus.emit('refreshList');
    } else {
      CommonUtils.showErrorInfo(ctx.context, res.desc);
    }
  }
}
